package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dto.AdChannel;
import com.heima.model.wemedia.dto.ChannelDto;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {

    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 查询频道列表
     * @return
     */
    @GetMapping("channels")
    public ResponseResult channels(){
        return wmChannelService.list();
    }

    /**
     * 频道名称模糊分页查询
     * @return
     */
    @PostMapping("list")
    public ResponseResult list(@RequestBody ChannelDto dto){
        return wmChannelService.listPage(dto);
    }

    /**
     * 删除频道
     */
    @GetMapping("del/{id}")
    public ResponseResult delete(@PathVariable Long id){
        //TODO:状态为1的时候不能删除
        wmChannelService.deleteById(id);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /**
     * 保存频道
     */
    @PostMapping("save")
    public ResponseResult save(@RequestBody AdChannel adChannel){
       return wmChannelService.save(adChannel);
    }

    /**
     * 修改频道
     */
    @PostMapping("update")
    public ResponseResult update(@RequestBody AdChannel adChannel){
        return wmChannelService.Adupdate(adChannel);
    }



}
